package com.danielepelagatti.flickrmanager.commands.photo
{
	import com.adobe.webapis.flickr.Photo;
	import com.adobe.webapis.flickr.events.FlickrResultEvent;
	import com.danielepelagatti.flickrmanager.commands.CommandHelper;
	import com.danielepelagatti.flickrmanager.commands.FlickrCommand;
	import com.danielepelagatti.flickrmanager.commands.IFlickrCommand;
	import com.danielepelagatti.flickrmanager.model.LocalUser;
	import com.theriabook.utils.Logger;
	/**
	 * 
	 * @author redde
	 * 
	 */
	public class GetPerms extends FlickrCommand implements IFlickrCommand
	{
		/**
		 * 
		 * @param event
		 * @return 
		 * 
		 */		
		public function error(event:FlickrResultEvent):Boolean
		{
			return false;
		}
		/**
		 * 
		 * @param event
		 * 
		 */		
		public function success(event:FlickrResultEvent):void
		{
			var result:Photo = event.data.photo as Photo;
			var pending:Photo = CommandHelper.getPhotoForOperation(event.type,result.id);
			if(pending)
			{
				var photo:Photo 			= LocalUser.getInstance().photoCollection.getPhotoById(result.id);
				photo.isFamily 				= result.isFamily;
				photo.isPublic 				= result.isPublic;
				photo.isFriend 				= result.isFriend;
				photo.commentPermission		= result.commentPermission;
				photo.addMetaPermission		= result.addMetaPermission;
				
				CommandHelper.removePhotoOperation(event.type,pending);
			}
			else
				Logger.error("GetPerms:: The result photo "+result.id+" doesn't correspond to any pending operation")		
		}
		/**
		 * 
		 * @return 
		 * 
		 */		
		public function getAPICall():Function
		{
			return flickr.photos.getPerms;
		}
		
	}
}